package com.batchengine.util;

import static com.batchengine.util.BatchPropertyReader.getBatchReader;
import static java.lang.Class.forName;
import static java.lang.String.format;
import static java.lang.System.getProperty;

/**
 * Created by sunil.incubator@yahoo.com.
 * User: sunil.kalva
 * Date: Jul 10, 2009
 */
public class EnvUtil {

    public static String ENVIRONMENT;

    public static String BASE_FOLDER_W;
    public static String BASE_FOLDER_L;

    public static String W_VM_FOLDER;
    public static String L_VM_FOLDER;

    public static String W_HTML_FOLDER;
    public static String L_HTML_FOLDER;

    public static String W_CONF_FOLDER;
    public static String L_CONF_FOLDER;

    public static String WINDOWS = "Window";

    static {

        ENVIRONMENT = getProperty("os.name");

        BASE_FOLDER_W = getBatchReader().getProperty("base.folder.w");
        BASE_FOLDER_L = getBatchReader().getProperty("base.folder.l");

        W_VM_FOLDER = format("%s/vm/", BASE_FOLDER_W);
        L_VM_FOLDER = format("%s/vm/", BASE_FOLDER_L);

        W_HTML_FOLDER = format("%s/html/", BASE_FOLDER_W);
        L_HTML_FOLDER = format("%s/html/", BASE_FOLDER_L);

        W_CONF_FOLDER = format("%s/conf/", BASE_FOLDER_W);
        L_CONF_FOLDER = format("%s/conf/", BASE_FOLDER_L);
    }

    public static Object createObjectz(String clazzName) {

        Object objectz = null;
        try {
            Class<?> aClass = forName(clazzName);
            objectz = aClass.newInstance();
        } catch(Exception ignored) {
            ignored.printStackTrace();
        }
        return objectz;
    }

    public static String getBaseFolderLocation() {

//        return BASE_FOLDER;
        if(ENVIRONMENT.contains(WINDOWS)) {
            return BASE_FOLDER_W;
        } else {
            return BASE_FOLDER_L;
        }
    }

    public static String getVMFolderLocation() {

//        return format("%s/settings/vm/", BASE_FOLDER);
        if(ENVIRONMENT.contains(WINDOWS)) {
            return W_VM_FOLDER;
        } else {
            return L_VM_FOLDER;
        }
    }

    public static String getConfFolderLocation() {

//        return format("%s/settings/conf/", BASE_FOLDER);
        if(ENVIRONMENT.contains(WINDOWS)) {
            return W_CONF_FOLDER;
        } else {
            return L_CONF_FOLDER;
        }
    }

    public static String getHTMLFolderLocation() {

//        return format("%s/settings/html/", BASE_FOLDER);
        if(ENVIRONMENT.contains(WINDOWS)) {
            return W_HTML_FOLDER;
        } else {
            return L_HTML_FOLDER;
        }
    }

}
